import './index.less';
import {getInformationList} from "../../utils/network/network.config";
import {getElement} from '../../utils/network/networkutils'

let tables=getElement('tables');
let toast=getElement('toast');
let tBody = tables.tBodies[0];
let allpgNumber=getElement('allpgnumber');
let upPage=getElement('uppage');
let downPage=getElement('downpage');
let nowPage=getElement('nowpage');
let flag=false;


//首屏加载
getData({});

downPage.onclick=function () {
        let pageNumber=nowPage.innerHTML;
        pageNumber=parseInt(pageNumber);
        pageNumber=pageNumber+1;
        getData({pageStart:(pageNumber-1)*15,pageNumber})
};
upPage.onclick=function () {
        let pageStart;
        let pageNumber=nowPage.innerHTML;
        pageNumber=parseInt(pageNumber);
        pageNumber=pageNumber-1;
        if (pageNumber===1){
            pageStart=0
        }else {
            pageStart=(pageNumber-1)*15;
        }
        getData({pageStart,pageNumber})
};
function getData(nowData) {
    let listData={
        pageStart:0,
        pageSize:15,
        pageNumber:1,
        ieStamp:new Date().getTime(),
        'isAjax':1,
    };
    listData={...listData,...nowData};
    getInformationList(listData).then(res=>{
        if(res.resultCode !== 'busi_ex'){
            let  result=res.data.result;
            let tableData=result.objects;
            let count=Math.ceil(result.count/15);
            if (listData.pageNumber>count){
                nowPage.innerHTML=count;
                return;
            }else if(listData.pageNumber<=0){
                nowPage.innerHTML=1;
                return;
            }
            allpgNumber.innerHTML=count;
            nowPage.innerHTML=listData.pageNumber;
            bindtBodyData(tableData)
        }
    })
}
function bindtBodyData(data) {
    let str = '';
    let billstatus;
    let approvedate;
    for (let i = 0; i < data.length; i++) {
        let item = data[i];
        if(item.billstatus===1){
            billstatus='<a '+'href='+'/carrieroperatordetails.html'+'?'+'pkTrialInfo='+item.pkTrialInfo+'>' +'未审批' + '</a>'
        }else{
            billstatus='已审批'
        }
        if (item.approvedate){
            approvedate=item.approvedate.slice(0,10);
        }else {
            approvedate=''
        }
        str += '<tr>';
        str += '<td>' +item.tenantname+ '</td>';
        str += '<td>' +item.linkman+ '</td>';
        str += '<td>' +item.mobilephone+ '</td>';
        str += '<td>' +item.email+ '</td>';
        str += '<td>' +item.province+ '</td>';
        str += '<td>' +item.city+ '</td>';
        str += '<td>' +item.county+ '</td>';
        str += '<td>' +item.detailaddress+ '</td>';
        str += '<td>' +billstatus+ '</td>';
        str += '<td>' +approvedate+ '</td>';
        str += '</tr>';
    }
    tBody.innerHTML = str;
}